import Vue from "vue";
import Router from "vue-router";
Vue.use(Router);
const router = new Router({
  routes: [
    { path: "/", redirect: "/login" },
    { path: "/login", component: () => import("./components/login.vue") },
    { path: "/home", component: () => import("./components/home.vue") }
  ]
});
// 挂载路由导航守卫
router.beforeEach((to,from,next)=>{
  if(to.path=="/login") return next()
  const token=sessionStorage.getItem("token")
  if(!token) return next("/login")
  next()
})
export default router;
